﻿{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>{{ ticket.create_time }}</title>
{#    <link rel="stylesheet" href="{% static 'css/reset.css' %}">#}
    <style rel="stylesheet">
        body{
            width: 9in;
        }
        table {
            width: 100%;}

        .itable_one {
            {#border-collapse:collapse;#}
            border:none;
            border-top: black 1px solid;
            border-left: black 1px solid;
        }
        .invoice_center td {
            border-right:solid #000 1px;
            border-bottom:solid #000 1px
        }
        .bottom_count {
            border-left: 1px solid #000;
        }

        body {
              margin: 0;
              padding: 0 8px;
            }

    </style>
</head>
<body>
<div class="invoice_top">
    <table>
        <tr><td colspan="7" style="text-align: center"><h2 class="i_title">{{title.head}}</h2></td></tr>
        <tr>
            <td>日期：</td>
            <td colspan="2">{{ ticket.create_time|date:"Y-m-d" }}</td>
            <td>单据编号：</td>
            <td colspan="2">{{ ticket.number }}</td>
        </tr>
        <tr><td>购买单位：</td><td>{{ ticket.organization.organization }}({{ ticket.organization.address }})</td><td>联系电话:</td><td>{{ ticket.handled_by.phone }}</td></tr>
    </table>
</div>
<div class="invoice_center">
    <table class="itable itable_one" cellspacing=0>
        <tr valign="top" align="center">
            <td style="width: 0.4in;">行号</td>
            <td  height="10px width: 2.5in;">商品名称</td>
            <td style="width: 0.7in;">规格</td>
            <td style="width: 0.6in;">单位</td>
            <td style="width: 0.6in;">数量</td>
            <td style="width: 0.8in;">单价</td>
            <td >金额</td>
            <td style="width: 2in;">备注</td>
        </tr>
        {% for good in goods %}
            <tr valign='top'>
                <td align="center">{{ forloop.counter }}</td>
                <td align='left'>{{ good.goods.name }}</td>
                <td align='left'>{{ good.goods.specification }}</td>
                <td align='center'>{{ good.goods.unit }}</td>
                <td align='right'>{{ good.amount }}{{ good.goods.unit }}&nbsp;</td>
                <td align='right'>{{ good.pries | floatformat:2 }}&nbsp;</td>
                <td align='right'>{{ good.total_pries | floatformat:2 }}&nbsp;</td>
                <td align='right'></td>
            </tr>
        {% endfor %}


    </table>
    <table cellspacing=0 class="bottom_count">
        <tr align="center">
            <td style="width: 1in;">合&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;计</td>
            <td colspan="5" align="left">(大写)&nbsp;<span id="g_money" class="i_mongey"></span></td>
            <td align="left" colspan="3">(小写)<span>&nbsp;￥</span><span id="i_money"
                                                                                     class="i_mongey">{{ ticket.total_pries | floatformat:2 }}</span>
            </td>
            <td style="width: 1.5in">总件数：{{sum_goods}}</td>
        </tr>
    </table>
</div>
<div>
    <table>
        <tr><td>地址：</td><td align="left">{{title.address}}</td><td>电话：</td><td align="left">{{title.number}}</td><td>手机：</td><td align="left">{{ title.phone }}</td></tr>
        <tr><td colspan="8">温馨提示：{{title.tip}}</td></tr>
    </table>
    <table>
        <tr>
            <td align="left">制单人：{{ title.make_by }}</td>
            <td align="left">送货人：{{ title.send_by }}</td>
            <td align="left">收货人：</td>
            <td>&nbsp;&nbsp;&nbsp;</td>
            <td>&nbsp;&nbsp;&nbsp;</td>
            <td>&nbsp;&nbsp;&nbsp;</td>
            <td>&nbsp;&nbsp;&nbsp;</td>
            <td>&nbsp;&nbsp;&nbsp;</td>
            <td>&nbsp;&nbsp;&nbsp;</td>
        </tr>
    </table>
</div>
</body>
{#<script src="js/jquery.min.js"></script>#}
{#<script src="js/imgalert.js"></script>#}
<script>
    function chineseNumber(dValue) {
        var maxDec = 2;
        dValue = dValue.toString().replace(/,/g, "");
        dValue = dValue.replace(/^0+/, "");
        if (dValue == "") {
            return "零";
        } else if (isNaN(dValue)) {
            return "错误：金额不是合法的数值！";
        }
        var minus = "";
        var CN_SYMBOL = "";
        if (dValue.length > 1) {
            if (dValue.indexOf('-') == 0) {
                dValue = dValue.replace("-", "");
                minus = "负";
            }
            if (dValue.indexOf('+') == 0) {
                dValue = dValue.replace("+", "");
            }
        }
        var vInt = "";
        var vDec = "";
        var resAIW;
        var parts;
        var digits, radices, bigRadices, decimals;
        var zeroCount;
        var i, p, d;
        var quotient, modulus;
        var NoneDecLen = (typeof (maxDec) == "undefined" || maxDec == null || Number(maxDec) < 0 || Number(maxDec) > 5);
        parts = dValue.split('.');
        if (parts.length > 1) {
            vInt = parts[0];
            vDec = parts[1];
            if (NoneDecLen) {
                maxDec = vDec.length > 5 ? 5 : vDec.length;
            }
            var rDec = Number("0." + vDec);
            rDec *= Math.pow(10, maxDec);
            rDec = Math.round(Math.abs(rDec));
            rDec /= Math.pow(10, maxDec);
            var aIntDec = rDec.toString().split('.');
            if (Number(aIntDec[0]) == 1) {
                vInt = (Number(vInt) + 1).toString();
            }
            if (aIntDec.length > 1) {
                vDec = aIntDec[1];
            } else {
                vDec = "";
            }
        } else {
            vInt = dValue;
            vDec = "";
            if (NoneDecLen) {
                maxDec = 0;
            }
        }
        if (vInt.length > 44) {
            return "错误：数值过大！整数位长【" + vInt.length.toString() + "】超过了上限！";
        }
        digits = new Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖");
        radices = new Array("", "拾", "佰", "仟");
        bigRadices = new Array("", "万", "亿", "兆", "京", "垓", "杼", "穰", "沟", "涧", "正");
        decimals = new Array("角", "分", "厘", "毫", "丝");
        resAIW = "";
        if (Number(vInt) > 0) {
            zeroCount = 0;
            for (i = 0; i < vInt.length; i++) {
                p = vInt.length - i - 1;
                d = vInt.substr(i, 1);
                quotient = p / 4;
                modulus = p % 4;
                if (d == "0") {
                    zeroCount++;
                } else {
                    if (zeroCount > 0) {
                        resAIW += digits[0];
                    }
                    zeroCount = 0;
                    resAIW += digits[Number(d)] + radices[modulus];
                }
                if (modulus == 0 && zeroCount < 4) {
                    resAIW += bigRadices[quotient];
                }
            }
            resAIW;
        }
        for (i = 0; i < vDec.length; i++) {
            d = vDec.substr(i, 1);
            if (d != "0") {
                resAIW += digits[Number(d)] + decimals[i];
            }
        }
        if (resAIW == "") {
            resAIW = "零";
        }
        if (vDec == "") {
            resAIW += "圆整";
        }
        resAIW = CN_SYMBOL + minus + resAIW;
        return resAIW;
    }

    i_money = document.getElementById("i_money");
    g_money = document.getElementById("g_money");
    g_money.innerText = chineseNumber(Number(i_money.innerText))

</script>
</html>